//
//  YGNetworkTool.swift
//  sinaWeiBoGui
//
//  Created by liyonggui on 16/5/12.
//  Copyright © 2016年 liyonggui. All rights reserved.
//

import UIKit

import AFNetworking

// 请求枚举
enum requesMethod: String {
    case GET = "GET"
    case POST = "POST"
}

class YGNetworkTool: NSObject {
    
    // 单例
    static let sharedInstance: YGNetworkTool = YGNetworkTool()
    
    // 属性
    private let AFNManager: AFHTTPSessionManager = {
       
        let afn = AFHTTPSessionManager(baseURL: NSURL(string: "https://api.weibo.com/"))
        afn.responseSerializer.acceptableContentTypes?.insert("text/plain")
        
        return afn
    }()
    
    ///  通过参数确定使用GET.POST方式
    ///
    ///  - parameter method:     使用GET / POST方式
    ///  - parameter URLString:  URLString
    ///  - parameter parameters: 参数
    ///  - parameter progress:   进程
    ///  - parameter success:    成功回调
    ///  - parameter failure:    失败回调
    func request(method: requesMethod, URLString: String, parameters: AnyObject?, success: ((NSURLSessionDataTask, AnyObject?) -> Void)?, failure: ((NSURLSessionDataTask?, NSError) -> Void)?) {
        if method == requesMethod.GET {
            AFNManager.GET(URLString, parameters: parameters, progress: nil, success: success, failure: failure)
        } else {
            AFNManager.POST(URLString, parameters: parameters, progress: nil, success: success, failure: failure)
        }
        
    }
   

}
